import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
import { dateFormatter } from '@/utils/formatTime'

// 表单校验
export const rules = reactive({
  siteId: [required],
  guestbookType: [required],
  title: [required],
  msgIp: [required],
  status: [required]
})

// CrudSchema https://doc.iocoder.cn/vue3/crud-schema/
const crudSchemas = reactive<CrudSchema[]>([
  {
    label: 'ID',
    field: 'id',
    isForm: false,
    isSearch: false
  },

  {
    label: '类型',
    field: 'guestbookType',
    isSearch: true,
    dictType: DICT_TYPE.CMS_GUESTBOOK_TYPE,
    dictClass: 'number',
    form: {
      component: 'SelectV2'
    }
  },
  {
    label: '留言标题',
    field: 'title',
    isSearch: true
  },
  {
    label: '留言内容',
    field: 'msgText',
    isSearch: false,
    isTable: false,
    form: {
      component: 'Input',
      componentProps: {
        type: 'textarea',
        rows: 8
      },
      colProps: {
        span: 24
      }
    }
  },

  {
    label: '联系人',
    field: 'contactUser',
    isSearch: false,
    isTable: false
  },
  {
    label: '昵称',
    field: 'nickname',
    isSearch: false,
    isTable: false
  },
  {
    label: '手机号',
    field: 'msgPhone',
    isSearch: true,
    isTable: false
  },
  {
    label: '电子邮箱',
    field: 'msgEmail',
    isSearch: true,
    isTable: false
  },
  {
    label: '联系地址',
    field: 'msgAddress',
    isSearch: false,
    isTable: false
  },
  {
    label: '公开',
    field: 'isOpen',
    isSearch: true,
    isTable: false,
    dictType: DICT_TYPE.CMS_STATUS_TYPE,
    dictClass: 'number',
    form: {
      component: 'Radio',
      value: 1
    }
  },
  {
    label: '回复',
    field: 'isReplied',
    isSearch: true,
    isTable: false,
    isForm: false,
    dictType: DICT_TYPE.CMS_STATUS_TYPE,
    dictClass: 'number'
  },
  {
    label: '推荐',
    field: 'recommended',
    isSearch: true,
    dictType: DICT_TYPE.CMS_STATUS_TYPE,
    dictClass: 'number',
    form: {
      component: 'Radio',
      value: 1
    }
  },
  {
    label: '状态',
    field: 'status',
    isSearch: true,
    dictType: DICT_TYPE.CMS_GUESTBOOK_STATUS,
    dictClass: 'number',
    form: {
      component: 'Radio',
      value: 1
    }
  },
  {
    label: '回复内容',
    field: 'replyText',
    isSearch: false,
    isTable: false,
    form: {
      component: 'Input',
      componentProps: {
        type: 'textarea',
        rows: 8
      },
      colProps: {
        span: 24
      }
    }
  },
  {
    label: '回复用户',
    field: 'replyUserName',
    isSearch: false,
    isForm: false
  },
  {
    label: '回复日期',
    field: 'replyDate',
    formatter: dateFormatter,
    isSearch: false,
    search: {
      component: 'DatePicker',
      componentProps: {
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
        type: 'daterange',
        defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')]
      }
    },
    form: {
      component: 'DatePicker',
      componentProps: {
        type: 'datetime'
      }
    }
  },
  {
    label: '站点ID',
    field: 'siteId',
    isSearch: false,
    isTable: false,
    isForm: false,
    form: {
      component: 'InputNumber',
      value: 0
    }
  },
  {
    label: 'IP地址',
    field: 'msgIp',
    isSearch: true,
    isTable: false,
    isForm: false
  },
  {
    label: '创建人',
    field: 'username',
    isSearch: false,
    isForm: false
  },
  {
    label: '创建时间',
    field: 'createTime',
    formatter: dateFormatter,
    isSearch: true,
    search: {
      component: 'DatePicker',
      componentProps: {
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
        type: 'daterange',
        defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')]
      }
    },
    isForm: false
  },
  {
    label: '操作',
    field: 'action',
    isForm: false
  }
])
export const { allSchemas } = useCrudSchemas(crudSchemas)
